<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: 12528
  Date: 2022/4/6
  Time: 19:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>信息查询列表</title>
    <link rel="stylesheet" type="text/css"
          href='<c:url context="${pageContext.request.contextPath}" value="/easyui/themes/default/easyui.css"/>'>
    <link rel="stylesheet" type="text/css"
          href='<c:url context="${pageContext.request.contextPath}" value="/easyui/themes/icon.css"/>'>
    <link rel="stylesheet" type="text/css"
          href='<c:url context="${pageContext.request.contextPath}" value="/easyui/css/demo.css"/>'>
    <script type="text/javascript"
            src='<c:url context="${pageContext.request.contextPath}" value="/easyui/jquery.min.js"/>'></script>
    <script type="text/javascript"
            src='<c:url context="${pageContext.request.contextPath}" value="/easyui/jquery.easyui.min.js"/>'></script>
    <script type="text/javascript"
            src='<c:url context="${pageContext.request.contextPath}" value="/easyui/js/validateExtends.js"/>'></script>
    <script type="text/javascript"
            src='<c:url context="${pageContext.request.contextPath}" value="/easyui/js/easyui-lang-zh_CN.js"/>'></script>

    <script type="text/javascript">

        $(function () {
            //datagrid初始化
            $('#dataList').datagrid({
                title: '信息查询列表',
                iconCls: 'icon-more',//图标
                border: true,
                collapsible: false,//是否可折叠的
                fit: true,//自动大小
                method: "get",
                url: "/MSOS/smsquery?action=data",
                idField: 'mid',
                singleSelect: false,//是否单选
                pagination: true,//分页控件
                rownumbers: true,//行号
                sortName: 'mid',
                sortOrder: 'ASC',
                remoteSort: false,
                columns: [[
                    {field: 'mid', title: '信息编号', width: 80, sortable: true},
                    {field: 'sephone', title: '发送方', width: 200},
                    {field: 'acphone', title: '接收方', width: 200},
                    {field: 'content', title: '信息内容', width: 200},
                    {field: 'sendDate', title: '发送时间', width: 200},
                    {field: 'chk', checkbox: true, width: 50},
                ]],
                toolbar: "#toolbar"
            });
            //设置分页控件
            var p = $('#dataList').datagrid('getPager');
            $(p).pagination({
                pageSize: 2,//每页显示的记录条数，默认为10
                pageList: [1, 4, 6, 8, 10],//可以设置每页记录条数的列表
                beforePageText: '第',//页数文本框前显示的汉字
                afterPageText: '页    共 {pages} 页',
                displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录',
            });

            //全选
            $("#selectAll").click(function () {
                $("#dataList").datagrid("checkAll");
            });

            //反选
            $("#selectOr").click(function () {
                //返回当前页的所有行
                var allRow = $("#dataList").datagrid("getRows")
                //返回当前选中的所有行
                var selectRow = $("#dataList").datagrid("getSelections");

                //如果选中行为空，就直接勾选所有行
                if (selectRow.length == 0) {
                    $("#dataList").datagrid("checkAll");
                } else {
                    for (var i = 0; i < allRow.length; i++) {
                        for (var j = 0; j < selectRow.length; j++) {
                            //判断是否为选中的行
                            if (allRow[i] == selectRow[j]) {
                                //选中则取消勾选
                                $("#dataList").datagrid("uncheckRow", i);
                            } else {
                                //未选中则勾选
                                $("#dataList").datagrid("checkRow", i);
                            }
                        }
                    }
                }
            });

            //全不选
            $("#selectNot").click(function () {
                $("#dataList").datagrid("clearChecked");
            });

            //删除
            $("#delete").click(function () {
                var selectRow = $("#dataList").datagrid("getSelected");
                if (selectRow == null) {
                    $.messager.alert("消息提醒", "请选择数据进行删除!", "warning");
                } else {
                    var clazzid = selectRow.mid;
                    $.messager.confirm("消息提醒", "将删除信息编号为：" + clazzid + "的短信记录，确认继续？", function (r) {
                        if (r) {
                            $.ajax({
                                type: "delete",
                                url: "/MSOS/smsquery?mid=" + clazzid,
                                success: function (msg) {
                                    if (msg.status == 200) {
                                        $.messager.alert("消息提醒", "删除成功!", "info");
                                        //刷新表格
                                        $("#dataList").datagrid("reload");
                                        //刷新下拉框
                                        $("#gradeList").combobox("reload");
                                    } else {
                                        $.messager.alert("消息提醒", msg.msg, "warning");
                                        return;
                                    }
                                }
                            });
                        }
                    });
                }
            });

            //日期下拉框
            $("#gradeList").combobox({
                width: "150",
                height: "25",
                valueField: "mid",
                textField: "sendDate",
                multiple: false, //不可多选
                editable: false, //不可编辑
                method: "get",
                url: "/MSOS/smsquery?action=data_from_smsquery",
                onChange: function (newValue, oldValue) {
                    if (newValue == -1) {
                        $('#dataList').datagrid("options").queryParams = {};
                    } else {
                        $('#dataList').datagrid("options").queryParams = {mid: newValue};
                    }
                    $('#dataList').datagrid("reload");
                }
            });

        });
    </script>
</head>
<body>
<!-- 数据列表 -->
<table id="dataList" cellspacing="0" cellpadding="0">
</table>

<!-- 工具栏 -->
<div id="toolbar">
    <div style="float: left;"><a id="selectAll" href="javascript:;" class="easyui-linkbutton" data-options="plain:true">全选</a></div>
    <div style="float: left;" class="datagrid-btn-separator"></div>
    <div style="float: left;"><a id="selectOr" href="javascript:;" class="easyui-linkbutton" data-options="plain:true">反选</a></div>
    <div style="float: left;" class="datagrid-btn-separator"></div>
    <div style="float: left;"><a id="selectNot" href="javascript:;" class="easyui-linkbutton" data-options="plain:true">全不选</a></div>
    <div style="float: left;" class="datagrid-btn-separator"></div>
    <div style="float: left; margin-right: 10px;"><a id="delete" href="javascript:;" class="easyui-linkbutton"
                                                     data-options="iconCls:'icon-some-delete',plain:true">删除</a></div>

    <div style="margin: 0 10px 0 10px">日期：<input id="gradeList" class="easyui-textbox" name="sendDate"/></div>
</div>

</body>
</html>
